// 全局缓存,用于供子页面翻译时使用
let globalCache = null;


// 根据传入的从缓存中寻找返回值
function commonRenderComma(tabName,ids) {

    if(globalCache!=null && globalCache!=undefined){

        if(public_isEmpty(tabName) || public_isEmpty(ids)){
            return ;
        }

        // 1.根据tabName得到缓存列表
        let cacheObjMap=globalCache[tabName];

        if(cacheObjMap!=null && cacheObjMap!=undefined){

            let idArray = ids.split(',');
            let nameArray = new Array();
            for(let id of idArray){
                if(!public_isEmpty(cacheObjMap[id].shortName)){
                    nameArray.push(cacheObjMap[id].shortName);
                }
                else{
                    nameArray.push(cacheObjMap[id].name);
                }
            }

            return nameArray.join();

        }
    }
}


/**
 * 从数字字典表中查询对应的全名，id格式为  id1,id2,id3
 * @param tabName
 * @param ids
 * @returns {Document.fullName}
 */
function getSysXtDicCacheNameByIds(tabName,ids) {
    if(globalCache != null && globalCache[tabName] != undefined){
        if(public_isEmpty(tabName) || public_isEmpty(ids)){
            return ;
        }

        let cacheObjMap = globalCache[tabName];
        if(cacheObjMap != null && cacheObjMap!=undefined){
            let idsArray = new String(ids).split(",");
            if(idsArray.length==0){
                return ;
            }

            let nameArray = new Array();

            for(let id of idsArray){
                let obj = cacheObjMap[id];
                if(obj!=null && obj!=undefined){
                    nameArray.push(obj.fullName);
                }
            }

            return nameArray.join();
        }
    }
}




// 根据id从sysDic缓存中取得全名
function getSysCacheFullName(tabName,id) {
    if(globalCache != null && globalCache[tabName] != undefined){
        if(public_isEmpty(tabName) || public_isEmpty(ids)){
            return ;
        }
        let cacheObjMap = globalCache[tabName];
        if(cacheObjMap != null && cacheObjMap!=undefined){
            let obj = cacheObjMap[id];
            if(obj!=null && obj!=undefined){
                let fullName = obj.fullName;
                return fullName;
            }
        }
    }
}

// 根据传入的表名，返回一个列表json对象
function getCacheList(tabName) {
    let list = new Array();
    if(globalCache!=null && globalCache[tabName]!=undefined){
        let cacheObjMap = globalCache[tabName];
        if(cacheObjMap!=null && cacheObjMap!=undefined){
            for(let key in cacheObjMap){
                list.push(cacheObjMap[key]);
            }
        }
    }
    return list;
}

// 根据缓存中的key找到对应的数组，再根据id找到对应的名称
function commonRendderNameByKeyAndId(cacheKey,id){
    if(globalCache!=null && globalCache!=undefined){
        let cacheObjMap = globalCache[cacheKey];
        if(cacheObjMap!=null && cacheObjMap!=undefined){
            let obj = cacheObjMap[id];
            if(obj!=null && obj!=undefined){
                return obj.name;
            }
        }
    }
}


//  根据缓存key 与 id 找到对象
function commonRendderObjByKeyAndId(cacheKey,id){
    if(globalCache!=null && globalCache!=undefined){
        let cacheObjMap = globalCache[cacheKey];
        if(cacheObjMap!=null && cacheObjMap!=undefined){
            let obj = cacheObjMap[id];
            if(obj!=null && obj!=undefined){
                return obj;
            }
        }
    }
}


// 根据传入的从缓存中寻找返回值
function getCacheValue(tabName,id) {

    if(globalCache!=null && globalCache!=undefined){
        // 1.根据tabName得到缓存列表
        let cacheObjMap=globalCache[tabName];
        if(cacheObjMap!=null && cacheObjMap!=undefined){
            let obj = cacheObjMap[id];
            if(obj!=null && obj!=undefined){
                let name = obj.name;
                if(name!=null && name!=undefined){
                    return name;
                }
            }
        }
    }
}

function commonRenderSysDicDropListByKey(tabName,key) {
    let jsonArray = new Array();
    if(globalCache!=null  && globalCache!=undefined){
        let cacheObjMap=globalCache[tabName];
        let pid = "";
        for(let objkey in cacheObjMap){
            let obj = cacheObjMap[objkey];
            if(obj!=null && obj!=undefined){
                if(obj.dicKey==key){
                    pid = obj.id;
                    break;
                }
            }
        }

        for(let objKey in cacheObjMap){
            let obj = cacheObjMap[objKey];
            if(obj!=null && obj!=undefined){
                if(obj.pid==pid){
                    jsonArray.push(obj);
                }
            }
        }
    }
    return jsonArray;
}

/**
 * 根据city的pid找到对应的列表
 * @param tableName
 * @param key
 * @returns {any[]}
 */
function commonRenderCityByPid(tabName,pid){
    let jsonArray=new Array();
    if(globalCache!=null  && globalCache[tabName]!=undefined){
        let cacheObjMap = globalCache[tabName];
        if(cacheObjMap!=null && cacheObjMap!=undefined){
            for(let key in cacheObjMap){
                let obj = cacheObjMap[key];
                if(obj!=null && obj!=undefined){
                    let objPid = obj.pid;
                    if(objPid!=null && objPid!=undefined && objPid==pid){
                        jsonArray.push(obj)
                    }
                }
            }
        }
    }
    return  jsonArray;
}

/**
 * 根据提货点类型，加载合票提货点信息
 * @param tabName
 * @param typeId
 * @returns {any[]}
 */
function commonRenderPickUpPointByTypeId(tabName,typeId){
    let jsonArray=new Array();
    if(globalCache!=null  && globalCache[tabName]!=undefined){
        let cacheObjMap = globalCache[tabName];
        if(cacheObjMap!=null && cacheObjMap!=undefined){
            for(let key in cacheObjMap){
                let obj = cacheObjMap[key];
                if(obj.pickUpTypeId==typeId){
                    jsonArray.push(obj);
                }
            }
        }
    }
    return  jsonArray;
}